package cn.com.xinjinfu.pdoulcProduct.activity.FixedProduct;

import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.com.xinjinfu.pdoulcProduct.R;
import cn.com.xinjinfu.pdoulcProduct.activity.base.BaseActivity;
import cn.com.xinjinfu.pdoulcProduct.activity.base.BaseWebActivity;
import cn.com.xinjinfu.pdoulcProduct.activity.login.CheckMobileActivity;
import cn.com.xinjinfu.pdoulcProduct.activity.recharge.BuyActivity;
import cn.com.xinjinfu.pdoulcProduct.activity.user.ActCertification;
import cn.com.xinjinfu.pdoulcProduct.adapter.HuankuanAdapter;
import cn.com.xinjinfu.pdoulcProduct.adapter.MenuItemAdapter;
import cn.com.xinjinfu.pdoulcProduct.common.ConstantValues;
import cn.com.xinjinfu.pdoulcProduct.engine.DataHandler;
import cn.com.xinjinfu.pdoulcProduct.entity.FixedProductInfoBean;
import cn.com.xinjinfu.pdoulcProduct.entity.InvestBills;
import cn.com.xinjinfu.pdoulcProduct.entity.User;
import cn.com.xinjinfu.pdoulcProduct.manager.AccountManager;
import cn.com.xinjinfu.pdoulcProduct.manager.ActivityManager;
import cn.com.xinjinfu.pdoulcProduct.manager.JSONManager;
import cn.com.xinjinfu.pdoulcProduct.manager.L;
import cn.com.xinjinfu.pdoulcProduct.manager.TitleManager;
import cn.com.xinjinfu.pdoulcProduct.manager.ToastManager;
import cn.com.xinjinfu.pdoulcProduct.utils.NewUtil;
import cn.com.xinjinfu.pdoulcProduct.utils.TextViewUtil;
import cn.com.xinjinfu.pdoulcProduct.view.BaseGridView;
import cn.com.xinjinfu.pdoulcProduct.view.FexidCircleProgressBar;
import cn.com.xinjinfu.pdoulcProduct.view.ListViewForScrollView;
import cn.com.xinjinfu.pdoulcProduct.view.LoadStatusBox;
import cn.com.xinjinfu.pdoulcProduct.view.TimeDownView;

/**
 * 定期标详情(公共)
 *  rettonStyle为0时是从首页列表跳转过来的
 *             为1 是从我的投资列表跳转过来
 *
 * Created by android-adt on 2016/1/4.
 */
public class FixedProductInfo extends BaseActivity implements View.OnClickListener {
    private TimeDownView timedownview;
    private FexidCircleProgressBar circleBar;
    private ScrollView sv_include;
    private RelativeLayout rl_title1;
    private LinearLayout ll_bidding, huikuanjihua, ll_borrower, ll_company, ll_house, ll_company_describe;
    private float percent = 0;
    private double shengyu;
    private LoadStatusBox loadbox;
    private String bidId, rettonStyle, investId, status;
    private Button bt_mairu;
    private RequestQueue requen;
    private MenuItemAdapter saMenuItem;
    private FixedProductInfoBean fixedProductInfoBean;
    private HuankuanAdapter adapter;
    private ArrayList<InvestBills> list;
    private TextView tv_bidding_status, top_title_tv, tv_status2, tv_bidding_cycle, tv_annual_yield, tv_annual_yield_rates, tv_method_repayment, tv_zonge01, tv_qitou, tv_shengyu,
            textView1_cycle, tv_object_name, tv_nian_shouyilv, tv_rongzi_money, tv_danbao_organization, tv_huankuan_style, tv_borrower_name, tv_id_number,
            tv_sex, tv_age, tv_marital_status, tv_company_describe, tv_company_name, tv_company_ceo, tv_company_money,
            tv_company_time, tv_company_friends, tv_error_hint, tv_current_city, tv_property_located, tv_building_area,
            tv_evaluated_price, tv_par, tv_lilv, tv_hetong, risk_info;
    private PopupWindow popupWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fixed_product_info_bidding);
        //初始化头布局
        TitleManager.showTitle(this, "", "");
        ActivityManager.getInstance().addActivity(this);
        findViewById(R.id.invest_details_mc).setVisibility(View.INVISIBLE);//在数据调用成功前默认不显示内容
        requen = Volley.newRequestQueue(this);
        list = new ArrayList<InvestBills>();
        Intent intent = getIntent();
        bidId = intent.getStringExtra("bidId");//得到对应的bidId值
        status = intent.getStringExtra("status");
        investId = intent.getStringExtra("investId");
        /**从不同页面跳转过来的状态值，0代表从首页理财列表跳转过来，1代表从我的P兜跳转*/
        rettonStyle = intent.getStringExtra("rettonStyle");
        initView();

        ListViewForScrollView list_huikuan = (ListViewForScrollView) findViewById(R.id.list_huikuan);
        adapter = new HuankuanAdapter(this);
        list_huikuan.setAdapter(adapter);
        adapter.setList(list);
    }

    public void initView() {
        loadbox = (LoadStatusBox) this.findViewById(R.id.loadStatusBox);
        loadbox.setOnClickListener(this);
        loadbox.loading();

        tv_hetong = (TextView) findViewById(R.id.tv_hetong);
        top_title_tv = (TextView) findViewById(R.id.top_title_tv);
        rl_title1 = (RelativeLayout) findViewById(R.id.rl_title1);
        tv_bidding_status = (TextView) findViewById(R.id.tv_bidding_status);
        tv_status2 = (TextView) findViewById(R.id.tv_status2);

        circleBar = (FexidCircleProgressBar) findViewById(R.id.circle);
        circleBar.setMaxstepnumber(10000);      //设置一圈的最大值
        tv_par = (TextView) findViewById(R.id.tv_par);
//        tv_lilv = (TextView) findViewById(R.id.tv_lilv);

        ll_borrower = (LinearLayout) findViewById(R.id.ll_borrower);
        ll_company = (LinearLayout) findViewById(R.id.ll_company);
        ll_house = (LinearLayout) findViewById(R.id.ll_house);
        ll_company_describe = (LinearLayout) findViewById(R.id.ll_company_describe);

        tv_company_describe = (TextView) findViewById(R.id.tv_company_describe);
        tv_company_name = (TextView) findViewById(R.id.tv_company_name);
        tv_company_time = (TextView) findViewById(R.id.tv_company_time);
        tv_company_ceo = (TextView) findViewById(R.id.tv_company_ceo);
        tv_company_money = (TextView) findViewById(R.id.tv_company_money);
        tv_company_friends = (TextView) findViewById(R.id.tv_company_friends);
        risk_info = (TextView) findViewById(R.id.risk_info);

        ll_bidding = (LinearLayout) findViewById(R.id.ll_bidding);
        huikuanjihua = (LinearLayout) findViewById(R.id.huikuanjihua);
        tv_error_hint = (TextView) findViewById(R.id.tv_error_hint);

        textView1_cycle = (TextView) findViewById(R.id.textView1_cycle);
        tv_bidding_cycle = (TextView) findViewById(R.id.tv_bidding_cycle);
        tv_annual_yield = (TextView) findViewById(R.id.tv_annual_yield);
        tv_annual_yield_rates = (TextView) findViewById(R.id.tv_annual_yield_rates);
        tv_method_repayment = (TextView) findViewById(R.id.tv_method_repayment);
        tv_zonge01 = (TextView) findViewById(R.id.tv_zonge01);
        tv_qitou = (TextView) findViewById(R.id.tv_qitou);
        tv_shengyu = (TextView) findViewById(R.id.tv_shengyu);
        timedownview = (TimeDownView) findViewById(R.id.timedownview);

        tv_object_name = (TextView) findViewById(R.id.tv_object_name);
        tv_nian_shouyilv = (TextView) findViewById(R.id.tv_nian_shouyilv);
        tv_rongzi_money = (TextView) findViewById(R.id.tv_rongzi_money);
        tv_danbao_organization = (TextView) findViewById(R.id.tv_danbao_organization);
        tv_huankuan_style = (TextView) findViewById(R.id.tv_huankuan_style);

        tv_borrower_name = (TextView) findViewById(R.id.tv_borrower_name);
        tv_id_number = (TextView) findViewById(R.id.tv_id_number);
        tv_sex = (TextView) findViewById(R.id.tv_sex);
        tv_age = (TextView) findViewById(R.id.tv_age);
        tv_marital_status = (TextView) findViewById(R.id.tv_marital_status);
        tv_current_city = (TextView) findViewById(R.id.tv_current_city);

        tv_property_located = (TextView) findViewById(R.id.tv_property_located);
        tv_building_area = (TextView) findViewById(R.id.tv_building_area);
        tv_evaluated_price = (TextView) findViewById(R.id.tv_evaluated_price);
        /**************禁止ScrollView自动滑动到底部*********************/
        sv_include = (ScrollView) findViewById(R.id.sv_include);
        disableAutoScrollToBottom();
        /** 最下面的GridView*/
        BaseGridView gridview = (BaseGridView) findViewById(R.id.gridView);
        saMenuItem = new MenuItemAdapter(this);
        gridview.setAdapter(saMenuItem);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                 System.out.println("click index:" + arg2);
                }
             }
        );
        bt_mairu = (Button) findViewById(R.id.bt_mairu);
        /*****查看合同******/
        tv_hetong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPopupWindow();
                int[] location = new int[2];
                v.getLocationOnScreen(location);// 获得指定控件的坐标
                popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1] + v.getHeight() + NewUtil.dip2px(FixedProductInfo.this,1));
            }
        });

    }


    public void upData() {
        if (fixedProductInfoBean != null) {
            top_title_tv.setText(fixedProductInfoBean.getBid().getTitle());
            /***
             * rettonStyle为0时是从首页列表跳转过来的
             */
            if (rettonStyle.equals("0")) {

                 /**** 正常购买详情页面 ******/
                if (status.equals("2") && fixedProductInfoBean.getBid().getLoanSchedule() < 100) {
                    /****         倒计时表头     ******/
                    rl_title1.setVisibility(View.VISIBLE);
                    tv_status2.setVisibility(View.GONE);
                    tv_bidding_status.setText("投标中");
                    daoJiShi();

                    /*** 圆形进度条 * */
                    ll_bidding.setVisibility(View.VISIBLE);
                    huikuanjihua.setVisibility(View.GONE);
                    percent = fixedProductInfoBean.getBid().getLoanSchedule();
                    if (percent > 0 && percent <= 1) {
                        percent = 1;
                    }else if (percent > 99 && percent < 100){
                        percent = 99;
                    }
                    if (percent > 0 && percent <= 10) {
                        circleBar.update(1000, 0);      //当比例小于10时增加显示效果强度，默认显示为10的进度
                    } else if (percent > 90 && percent < 100){
                        circleBar.update( 90 * 100, 0);
                    }else {
                        circleBar.update((int) percent * 100, 0);
                    }
                    tv_par.setText((int)Math.floor(percent)+ "%");

//                    tv_lilv.setText(NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getApr()));
                    tv_zonge01.setText(TextViewUtil.getSumLength(fixedProductInfoBean.getBid().getAmount()));
                    tv_qitou.setText(TextViewUtil.getSumLength(fixedProductInfoBean.getBid().getMinInvestAmount()));
                    shengyu = fixedProductInfoBean.getBid().getAmount() - fixedProductInfoBean.getBid().getHasInvestedAmount();
                    tv_shengyu.setText(TextViewUtil.getSumLength(shengyu));
                    bt_mairu.setVisibility(View.VISIBLE);
                    bt_mairu.setText("立刻购买");
                    bt_mairu.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            User user = AccountManager.getInstance().getUser();
                            if (user != null && user.getCurrUser().isLogged()) {
                                if (user.getCurrUser().getIdNumber() == null) {
                                    Intent intent0 = new Intent();
                                    intent0.putExtra("cer_style_falg", 1);
                                    intent0.setClass(FixedProductInfo.this, ActCertification.class);
                                    startActivity(intent0);
                                    ToastManager.showShort(FixedProductInfo.this, "请先进行实名认证！");
                                }else {
                                    Intent intent = new Intent(FixedProductInfo.this, BuyActivity.class);
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("objBuy", 1);
                                    bundle.putString("Id", bidId);
                                    bundle.putString("titlename", fixedProductInfoBean.getBid().getTitle());
                                    intent.putExtras(bundle);
                                    startActivity(intent);
                                }
                            } else {
                                startActivity(new Intent(FixedProductInfo.this, CheckMobileActivity.class));
                            }

                        }
                    });
                } else if (status.equals("2") || status.equals("3") && fixedProductInfoBean.getBid().getLoanSchedule() == 100) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("待放款");
                    tv_status2.setTextColor(0xFF6ED3D6);

                    ll_bidding.setVisibility(View.GONE);
                    huikuanjihua.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.GONE);
                } else if (status.equals("4")) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("还款中");
                    tv_status2.setTextColor(0xFF6ED3D6);

                    ll_bidding.setVisibility(View.GONE);
                    huikuanjihua.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.GONE);

                } else if (status.equals("5")) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("已结束");
                    tv_status2.setTextColor(0xFF999999);

                    ll_bidding.setVisibility(View.GONE);
                    huikuanjihua.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.GONE);
                }
                huikuanjihua.setVisibility(View.GONE);
            } else {/*******************rettonStyle为其他 是从我的投资列表跳转过来的*****/
                if (status.equals("1")) {
                    /***
                     * 倒计时表头
                     */
                    rl_title1.setVisibility(View.VISIBLE);
                    tv_status2.setVisibility(View.GONE);
                    tv_bidding_status.setText("投标中");
                    daoJiShi();
                    /**
                     * 圆形进度条
                     * */
                    ll_bidding.setVisibility(View.VISIBLE);
                    percent = fixedProductInfoBean.getBid().getLoanSchedule();
                    if (percent > 0 && percent <= 1) {
                        percent = 1;
                    }else if (percent > 99 && percent < 100){
                        percent = 99;
                    }
                    if (percent > 0 && percent <= 10) {
                        circleBar.update(1000, 0);      //当比例小于10时增加显示效果强度，默认显示为10的进度
                    } else if (percent > 90 && percent < 100){
                        circleBar.update( 90 * 100, 0);
                    }else {
                        circleBar.update((int) percent * 100, 0);
                    }

                    tv_par.setText((int)Math.floor(percent)+ "%");
//                    tv_lilv.setText(NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getApr()));

                    tv_zonge01.setText(TextViewUtil.getSumLength(fixedProductInfoBean.getBid().getAmount()));
                    tv_qitou.setText(TextViewUtil.getSumLength(fixedProductInfoBean.getBid().getMinInvestAmount()));
                    tv_shengyu.setText(TextViewUtil.getSumLength(fixedProductInfoBean.getBid().getAmount() - fixedProductInfoBean.getBid().getHasInvestedAmount()));
                    bt_mairu.setVisibility(View.VISIBLE);
                    bt_mairu.setText("立刻购买");
                    bt_mairu.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(FixedProductInfo.this, BuyActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putInt("objBuy", 1);
                            bundle.putString("Id", bidId);
                            bundle.putString("titlename", fixedProductInfoBean.getBid().getTitle());
                            intent.putExtras(bundle);
                            startActivity(intent);
                        }
                    });
                    if (fixedProductInfoBean.getBid().getBidType() == 2 && fixedProductInfoBean.getCanbuy() > 0){
                        bt_mairu.setText("新手标仅限首次购买");
                        bt_mairu.setTextSize(15);
                        bt_mairu.setBackgroundColor(0xFFCCCCCC);
                        bt_mairu.setEnabled(false);
                    }
                } else if (status.equals("2")) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("待放款");
                    tv_status2.setTextColor(0xFF6ED3D6);

                    ll_bidding.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.GONE);
                } else if (status.equals("4") || status.equals("6")) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("已结束");
                    tv_status2.setTextColor(0xFF999999);

                    ll_bidding.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.GONE);
                } else if (status.equals("5")) {
                    rl_title1.setVisibility(View.GONE);
                    tv_status2.setVisibility(View.VISIBLE);
                    tv_status2.setText("还款中");
                    tv_status2.setTextColor(0xFF6ED3D6);

                    ll_bidding.setVisibility(View.GONE);
                    bt_mairu.setVisibility(View.VISIBLE);
                    if (fixedProductInfoBean.getHavCoupons()>0){
                        bt_mairu.setText("购买时已使用兜券，不可转让");
                        bt_mairu.setTextSize(15);
                        bt_mairu.setBackgroundColor(0xFFCCCCCC);
                    }else if (fixedProductInfoBean.getBid().getBidType() == 2){
                        bt_mairu.setText("新手标不可转让");
                        bt_mairu.setTextSize(15);
                        bt_mairu.setBackgroundColor(0xFFCCCCCC);
                    }else{
                        bt_mairu.setText("转让");
                        bt_mairu.setBackgroundColor(0xFFF77F96);
                        bt_mairu.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (fixedProductInfoBean.getTransferLimit() > 0) {
                                    ToastManager.showShort(FixedProductInfo.this, "标的还款日，无法发起转让");
                                } else if (fixedProductInfoBean.getOverdue() > 0) {
                                    ToastManager.showShort(FixedProductInfo.this, "该标的已逾期，无法发起转让");
                                } else {
//                                FixedProductInfo.this.finish();
                                    Intent intent = new Intent(FixedProductInfo.this, TransferProInfoResult.class);
                                    intent.putExtra("investId", investId);
                                    startActivity(intent);
                                }
                            }
                        });
                    }
                    if (fixedProductInfoBean.getLockTranfer() > 0) {
                        bt_mairu.setText("锁定期" + fixedProductInfoBean.getLockTimeBefore() + "-" + fixedProductInfoBean.getLockTimeAfter());
                        bt_mairu.setBackgroundColor(0xFFCCCCCC);
                        bt_mairu.setTextSize(15);
                        bt_mairu.setEnabled(false);
                    }
                }



                /****        回款计划           *****/
                if (fixedProductInfoBean.getInvestBills() != null && !fixedProductInfoBean.getInvestBills().isEmpty()) {
                    huikuanjihua.setVisibility(View.VISIBLE);
                    if (fixedProductInfoBean.getJsonprepayment().getPrepaymentstatus() != 0) {
                        tv_error_hint.setVisibility(View.VISIBLE);
                        tv_error_hint.setText("*借款人于" + fixedProductInfoBean.getJsonprepayment().getYear() + "年" +
                                fixedProductInfoBean.getJsonprepayment().getMonth() + "月" + fixedProductInfoBean.getJsonprepayment().getDay() + "日提前还本" +
                                TextViewUtil.getSumLength(fixedProductInfoBean.getJsonprepayment().getSunmoney()) + "元，罚息" +
                                TextViewUtil.getSumLength(fixedProductInfoBean.getJsonprepayment().getDefaultinterest()) + "元");
                    }
                }else {
                    huikuanjihua.setVisibility(View.GONE);
                }
            }

            /**
             * 公共信息
             */
            int id = fixedProductInfoBean.getBid().getProductId();
            if (id == 7) {
                ll_company_describe.setVisibility(View.VISIBLE);
                ll_borrower.setVisibility(View.GONE);
                ll_company.setVisibility(View.VISIBLE);
                ll_house.setVisibility(View.GONE);
                tv_company_describe.setText("   " + fixedProductInfoBean.getBid().getDescription());
                tv_company_name.setText(fixedProductInfoBean.getBid().getCompanyName());
                String time = fixedProductInfoBean.getBid().getSetupTime();
                String show_id = time.substring(0, 2) + "**" + time.substring(4);
                tv_company_time.setText(show_id);
                tv_company_ceo.setText(fixedProductInfoBean.getBid().getCompanyLegal().substring(0, 1) + "**");
                tv_company_money.setText(fixedProductInfoBean.getBid().getRegisterCapital());
                tv_company_friends.setText(fixedProductInfoBean.getBid().getCooperation());

            } else if (id == 1 || id == 11) {
                ll_company_describe.setVisibility(View.GONE);
                ll_borrower.setVisibility(View.VISIBLE);
                ll_company.setVisibility(View.GONE);
                ll_house.setVisibility(View.VISIBLE);
            } else {
                ll_company_describe.setVisibility(View.GONE);
                ll_borrower.setVisibility(View.VISIBLE);
                ll_company.setVisibility(View.GONE);
                ll_house.setVisibility(View.GONE);
            }


            if (fixedProductInfoBean.getBid().getPeriodUnit() == -1) {
                textView1_cycle.setText("期限(年)");
            } else if (fixedProductInfoBean.getBid().getPeriodUnit() == 0) {
                textView1_cycle.setText("期限(月)");
            } else if (fixedProductInfoBean.getBid().getPeriodUnit() == 1) {
                textView1_cycle.setText("期限(天)");
            }
            tv_bidding_cycle.setText(fixedProductInfoBean.getBid().getPeriod() + "");
            tv_annual_yield.setText(NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getApr() -
                    fixedProductInfoBean.getBid().getDiscount()) + "%");
            if (String.valueOf(fixedProductInfoBean.getBid().getDiscount()) != "0.0") {
                tv_annual_yield_rates.setVisibility(View.VISIBLE);
                tv_annual_yield_rates.setText("+" + NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getDiscount()) + "%");
            }

            if (fixedProductInfoBean.getBid().getRepayment().getId() == 1) {
                tv_method_repayment.setText("按月等额本息");
            } else if (fixedProductInfoBean.getBid().getRepayment().getId() == 2) {
                tv_method_repayment.setText("按月先息后本");
            } else if (fixedProductInfoBean.getBid().getRepayment().getId() == 3) {
                tv_method_repayment.setText("一次性还款");
            }

            //基本信息
            tv_object_name.setText(fixedProductInfoBean.getBid().getTitle());
            tv_nian_shouyilv.setText(NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getApr()) + "%");
            tv_rongzi_money.setText(NumberFormat.getInstance().format(fixedProductInfoBean.getBid().getAmount() / 10000) + " 万");//融资近额  100万
            tv_danbao_organization.setText(fixedProductInfoBean.getBid().getAgencyName());                //揭开
            tv_huankuan_style.setText(fixedProductInfoBean.getBid().getRepayment().getName());

            //借款人信息id.substring(0, 3) + "********" + id.substring(14);
            tv_borrower_name.setText(fixedProductInfoBean.getBid().getUser().getRealityName().substring(0, 1) + "**");
            tv_id_number.setText(fixedProductInfoBean.getBid().getUser().getIdNumber().substring(0, 4) + "*******"
                    + fixedProductInfoBean.getBid().getUser().getIdNumber()
                    .substring(fixedProductInfoBean.getBid().getUser().getIdNumber().length()));
            tv_sex.setText(fixedProductInfoBean.getBid().getUser().getSex());
            tv_age.setText(fixedProductInfoBean.getBid().getUser().getAge() + "");
            tv_marital_status.setText(fixedProductInfoBean.getBid().getUser().getMaritalName());
            tv_current_city.setText(fixedProductInfoBean.getBid().getUser().getAddress());

            //房产信息
            if (fixedProductInfoBean.getBid().getLocation() != null
                    && fixedProductInfoBean.getBid().getLocation().length() >= 8){
                tv_property_located.setText(fixedProductInfoBean.getBid().getLocation().substring(0, 8) + "********");
            }else {
                tv_property_located.setText(fixedProductInfoBean.getBid().getLocation());
            }
            tv_building_area.setText(fixedProductInfoBean.getBid().getBuildArea() + "㎡");
            tv_evaluated_price.setText(fixedProductInfoBean.getBid().getAssessmentPrice());

            //风控信息
            risk_info.setText(Html.fromHtml(fixedProductInfoBean.getBid().getRiskInfo()));
            List<String> page = fixedProductInfoBean.getAudititems();
            saMenuItem.setList(page);
            saMenuItem.notifyDataSetChanged();
        }
    }

    /**
     * 网络请求
     */
    private void loginRequest(String url) {
        if (!DataHandler.isNetworkConnected(this)) {
            loadbox.failed();
            return;
        }
        final Map<String, String> parameters = DataHandler.getParameters(url);
        parameters.put("bidId", bidId);
        User user = AccountManager.getInstance().getUser();
        if (user != null ) {
            parameters.put("id", user.getCurrUser().getSign());
        }
        if (url.equals("1209")){
            parameters.put("investId", investId);
        }
        JsonObjectRequest request = new JsonObjectRequest(DataHandler.getBuildUrl(parameters), null, succeedRespon, DataHandler.getEor(this, loadbox));
        request.setRetryPolicy(new DefaultRetryPolicy(ConstantValues.TIMEOUT, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        requen.add(request);

    }

    private Response.Listener<JSONObject> succeedRespon = new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject jobj) {
            L.d("定期jobj=============" + jobj.toString());
            if (JSONManager.getError(jobj) == -1) {
                initData(jobj);
            } else {
                loadbox.failed();
                ToastManager.showShort(FixedProductInfo.this, JSONManager.getMsg(jobj));
            }

        }

    };

    protected void initData(JSONObject jobj) {
        list.clear();
        adapter.notifyDataSetChanged();
        loadbox.success();
        findViewById(R.id.invest_details_mc).setVisibility(View.VISIBLE);//在数据调用成功后显示页面内容
        fixedProductInfoBean = JSON.parseObject(jobj.toString(), FixedProductInfoBean.class);
        List<InvestBills> listdata = fixedProductInfoBean.getInvestBills();
        if (listdata != null) {
            for (InvestBills item : listdata) {
                InvestBills item2 = new InvestBills();
                item2.setPeriods(item.getPeriods());
                item2.setReceive_amount(item.getReceive_amount());
                item2.setReceive_corpus(item.getReceive_corpus());
                item2.setReal_receive_corpus(item.getReal_receive_corpus());
                item2.setReceive_interest(item.getReceive_interest());
                item2.setReal_receive_interest(item.getReal_receive_interest());
                item2.setReceive_time(item.getReceive_time());
                item2.setReal_receive_time(item.getReal_receive_time());
                item2.setStatus(item.getStatus());
                item2.setIsben(true);
                if (fixedProductInfoBean.getJsonprepayment().getPrepaymentstatus() > 0) { //提前还款
                    if (item.getReal_receive_interest() != 0)
                        list.add(item);
                    if (item.getReal_receive_corpus() != 0)
                        list.add(item2);
                }else {
                    if (item.getReceive_interest() != 0)
                        list.add(item);
                    if (item.getReceive_corpus() != 0)
                        list.add(item2);
                }
            }
            adapter.notifyDataSetChanged();
        }
        upData();
    }

    @Override
    public void onClick(View v) {
        if (!NewUtil.checkClick(v.getId())) return;
        User user = AccountManager.getInstance().getUser();
        String url;
        Intent intent = new Intent(this, BaseWebActivity.class);
        Bundle bundle = new Bundle();
        switch (v.getId()) {
            case R.id.loadStatusBox:
                //刷新请求
                if (rettonStyle.equals("1")) {
                    if (status.equals("4") || status.equals("5") || status.equals("6")) {
                        loginRequest("1209");
                    } else {
                        loginRequest("1205");
                    }
                } else {
                    loginRequest("1205");
                }
                break;

            case R.id.borrow_hetong:
                url = DataHandler.WEBURL + "/front/wa/querycompact?investId=" + investId + "&compacttype=3&id=" + user.getCurrUser().getSign();
                bundle.putString("url", url);
                bundle.putString("title", "借款合同");
                intent.putExtras(bundle);
                startActivity(intent);
                clossPopupWindow();
                break;
            case R.id.jujian_xieyi:
                url = DataHandler.WEBURL + "/front/wa/querycompact?investId=" + investId + "&compacttype=3&id=" + user.getCurrUser().getSign();
                bundle.putString("url", url);
                bundle.putString("title", "居间协议");
                intent.putExtras(bundle);
                startActivity(intent);
                clossPopupWindow();
                break;
        }
    }

    /**
     * 防止Scroll包裹的gridview内容显示不全
     */
    private void disableAutoScrollToBottom() {
        sv_include.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        sv_include.setFocusable(true);
        sv_include.setFocusableInTouchMode(true);
        sv_include.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.requestFocusFromTouch();
                return false;
            }
        });
    }

    /**
     * ****************  倒计时 **************
     */
    public void daoJiShi() {
        long diff = (fixedProductInfoBean.getExpireTime().getTime()
                - fixedProductInfoBean.getNowTime().getTime())/1000;
        L.d("倒计时" + diff);
        long[] time;
        if (diff <= 0) {
            time = new long[]{0, 0, 0};
        } else {
            long hours = diff / (60 * 60);
            long minutes = (diff%(60 * 60)) / 60;
            long second = diff%(60 * 60) % 60;
            time = new long[]{hours, minutes, second};
        }
        timedownview.setTimes(time);
        if (!timedownview.isRun()) {
            timedownview.run();
        }
    }



    /**
     * 获取PopupWindow实例
     */
    private void getPopupWindow() {
        if (null != popupWindow) {
            popupWindow.dismiss();
            return;
        } else {
            initPopuptWindow();
        }
    }
    private void clossPopupWindow() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            popupWindow = null;
        }
    }
    /**
     * 创建查看合同PopupWindow
     */
    protected void initPopuptWindow() {
        View view = getLayoutInflater().inflate(R.layout.popupwindow_hetong, null, false);
        Button borrow_hetong = (Button) view.findViewById(R.id.borrow_hetong);
        LinearLayout ll_zhuanrang = (LinearLayout) view.findViewById(R.id.ll_zhuanrang);
        ll_zhuanrang.setVisibility(View.GONE);
        Button jujian_xieyi = (Button) view.findViewById(R.id.jujian_xieyi);
        borrow_hetong.setOnClickListener(this);
        jujian_xieyi.setOnClickListener(this);
        // 创建PopupWindow实例,200,LayoutParams.MATCH_PARENT分别是宽度和高度
        popupWindow = new PopupWindow(view, NewUtil.dip2px(this,100.0f), ActionBar.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setOutsideTouchable(true);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                clossPopupWindow();
                return true;
            }
        });
    }


}